//
//  ViewController.m
//  test
//
//  Created by 文道江 on 15-1-20.
//  Copyright (c) 2015年 文道江. All rights reserved.
//

#import "ViewController.h"
#import "MBProgressHUD.h"

@interface ViewController (){
    UITextView *textView;
}

@property(nonatomic, strong)MBProgressHUD *hud;
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    UIBarButtonItem *refresh = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(myTask)];
    [refresh setTintColor:[UIColor whiteColor]];
    
    [self.navigationItem setRightBarButtonItem:refresh animated:YES];
    
    [self setTitle:@"岗位大厅"];
    
    textView = [[UITextView alloc]initWithFrame:self.view.bounds];
    
    [self.view addSubview:textView];
    
    self.hud = [[MBProgressHUD alloc]initWithView: self.view];
    [self.view addSubview: self.hud];
    self.hud.square = YES;
    
    [self myTask];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    
}

- (void)myTask{
    
    self.hud.labelText = @"正在拼命为您加载...";
    self.hud.layer.bounds = CGRectMake(self.hud.layer.frame.origin.x,
                                      self.hud.layer.frame.origin.y,
                                      self.hud.layer.frame.size.width,
                                      50);
    [self.hud show:YES];
    
    [NSURLConnection
     sendAsynchronousRequest:
     [NSURLRequest requestWithURL:
      [NSURL URLWithString:@"http://192.168.1.10/info.php"]]
     queue:[[NSOperationQueue alloc]init]
     completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
         NSLog(@"%@", [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]);
         dispatch_async(dispatch_get_main_queue(), ^{
             [textView setText: [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]];
             [_hud hide:YES];
         });
     }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
